<?php
class M_managebank extends CI_Model{
	function data_bank($key){
		$result = "";
		$kuery = "SELECT * FROM m_bank";
		if($key !== ""){
			$kuery .= " WHERE LOWER(m_bank.bank_name) LIKE '%" . strtolower($key) . "%'";
		}
		$query = $this->db->query($kuery);
		$num_rows = $query->num_rows();
		if($num_rows > 0){
			$result=$query->result();
			foreach($result as $row_result){
				$data[] = $row_result;
			}
			$result = json_encode($data);
		}
		return $result;
	}
	function bank_add($bank_nama,$bank_norek){
		$kuery = "INSERT INTO m_bank(bank_name, bank_rek) 
			VALUES ('" . $bank_nama . "','" . $bank_norek . "')";
		$query = $this->db->query($kuery);
		if($this->db->affected_rows()){
			return 1;
		}else{
			return 0;
		}
	}
	function bank_edit($bank_id,$bank_nama,$bank_norek){
		$kuery = "UPDATE m_bank SET bank_name = '" . $bank_nama . "',bank_rek = '" . $bank_norek . "'
			WHERE bank_id = '" . $bank_id . "'";
		$query = $this->db->query($kuery);
		if($this->db->affected_rows()){
			return 1;
		}else{
			return 0;
		}
	}
	function bank_delete($bank_id){
		$kuery = "DELETE FROM m_bank WHERE bank_id = '" . $bank_id . "'";
		$query = $this->db->query($kuery);
		if($this->db->affected_rows()){
			return 1;
		}else{
			return 0;
		}
	}
}
?>